<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html class="win-frame">
<head>
<title>${name_china}管理-编辑${name_china}</title>
<%@include file="/common/head.jsp" %>

<!-- 上传下载插件 -->
 <link href="<%=request.getContextPath()%>/static/plugin/uploadify/style/uploadify.css" rel="stylesheet">
 <script src="<%=request.getContextPath()%>/static/plugin/uploadify/js/jquery.uploadify.js"></script>

<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>

<!--富文本插件 -->
<script src="<%=request.getContextPath()%>/static/plugin/ckeditor/ckeditor.js"></script>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
            <span class="split"></span>
            <span>编辑${name_china}</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<form id="form" method="post">
    <div class="form-wrapper">
	  <div class="h4 distance-double">
        <span class="h4-title"><i class="icon icon-setting"></i>基本信息</span>
        <span class="h4-border"></span>
      </div>
      
      <input type="hidden" id="id" name="id"/>
      
	     
	        
	     <div class="form-cont">
	         <p class="form-cont-title"><span class="field-required">*</span>商品类别</p>
	         <input type="text" id="categoryId" name="categoryId" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[50]']"/> 
	         <input type="text" id="productId" name="productId" class="summer-input summer-validatebox"/> 
	     </div>
	     
	     <h3>商品SPU</h3>
    <table id="product" class="table-view" style="margin-left: 180px;">
        <tr>
	       <td class="td-title">商品名称</td>
	       <td><span id="name"></span></td>
        </tr>
        <tr>
	       <td class="td-title">商品品牌</td>
	       <td><span id="brand"></span></td>
        </tr>
        
         <tr>
	       <td class="td-title">佣金比例</td>
	       <td><span id="marketProfitPercent"></span></td>
        </tr>
        
         <tr>
	       <td class="td-title">商品主图</td>
	       <td><span id="mainImageUrl"></span></td>
        </tr>
          <tr>
	       <td class="td-title">商品详情图</td>
	       <td><span id="detailImageUrls"></span></td>
        </tr>
        
        <tr>
	       <td class="td-title">商品基本原价</td>
	       <td><span id="productOrginPrice"></span></td>
        </tr>
         <tr>
	       <td class="td-title">商品优惠红包金额</td>
	       <td><span id="productHongbao"></span></td>
        </tr>
          <tr>
	       <td class="td-title">商品基本价</td>
	       <td><span id="productPrice"></span></td>
        </tr>
        <tr>
	       <td class="td-title">备注</td>
	       <td><span id="note"></span></td>
        </tr>
    </table>
    
	      <div class="form-cont">
	        <p class="form-cont-title">是否自动延期</p>
	        <input type="text" id="isAutoRenew" name="isAutoRenew" class="summer-input summer-validatebox"  data-validatebox="validType:['required']"/> 
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title">秒杀价格</p>
	        <input type="text" id="seckillPrice" name="seckillPrice" class="summer-input"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">秒杀时段</p>
	        <input type="text" id="seckillTime" name="seckillTime" class="summer-input"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">秒杀库存</p>
	        <input type="text" id="limitCount" name="limitCount" class="summer-input"/> 
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title">备注</p>
	        <textarea class="summer-textarea" id="note" name="note"></textarea>
	     </div>
	      
     
     <div class="form-btn-wrapper" id="funcbar">
        <a class="btn btn-normal" id="backBtn">关闭</a>
    </div>
  </div>
</form>
<script>
    
  var   editData,
        editDataProduct,
        permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	editData = ${editData};
    	editDataProduct = ${editDataProduct};
    	
    	//初始化funcbar
     	$('#funcbar').prepend($.funcbar({
            type: 'button',
            data: permission,
            permit: ['${name_english}:edit']
        }));
    	
     	//初始化下拉选项
    	$('#isAutoRenew').combobox({
    		    async:false,
	    		defaultValue : editData.isAutoRenew,
	            valueField : 'code',
	            textField : 'name',
	            url : COMMON_URL.getCode + '?type=T_DM_COMMON_YESORNOT'
        });
     	
    	  //初始化下拉选项
    	  $('#seckillTime').combobox({
    		    async:false,
	    		defaultValue : editData.seckillTime,
	            valueField : 'code',
	            textField : 'name',
	            url : COMMON_URL.getCode + '?type=T_DM_MALL_SECKILL_TIME'
        });
    	  
    	  $("#seckillPrice").val(editData.seckillPrice);
    	  $("#limitCount").val(editData.limitCount);
    	  $("#note").val(editData.note);
 		  //$("#productId").val(editData.productId);
    	  
    		//初始化商品名称
         	$('#productId').combobox({
      		    async:false,
      		    defaultValue:editData.productId,
  	            valueField : 'id',
  	            textField : 'name',
  	            onSelect: function (product){
  	            	   $("#name").html(product.name);
                     	$("#brand").html(product.brand);
                     	$("#marketProfitPercent").html(product.marketProfitPercent);
                     	$("#mainImageUrl").html("<img style='heiht:80px;width:80px;' src=\'"+product.mainImageUrl+"\'/>");
                     	
                     	var detailImageUrls="";
                     	if( product.detailImageUrls ){
                     		var images = product.detailImageUrls.split(',');
                     		for( var i=0; i<images.length; i++ ){
                     			detailImageUrls += "<img style='heiht:80px;width:80px;' src=\'"+product.detailImageUrls+"\'/>";
                     		}
                     	}
                     	
                     	$("#detailImageUrls").html(detailImageUrls);
                     	$("#productOrginPrice").html(product.productOrginPrice);
                     	$("#productHongbao").html(product.productHongbao);
                     	$("#productPrice").html(product.productPrice);
                     	$("#note").html(product.note);
  	            },
                  url: CONST_URL.GET_PRODUCTS+"?categoryId="+editData.categoryId
      	}); 
       	//初始化下拉选项
       	 $('#categoryId').combobox({
       		   defaultValue:editData.categoryId,
       		   async:false,
               valueField : 'id',
               textField : 'name',
               onSelect: function (category){
            	   //alert(category.id)
               	    $('#productId').combobox({
                       valueField : 'id',
                       textField : 'name',
                       onSelect: function (product){
	                       	//alert(record.name+'/////'+record.productPrice);
	                       	$("#name").html(product.name);
	                       	$("#brand").html(product.brand);
	                       	$("#marketProfitPercent").html(product.marketProfitPercent);
	                       	$("#mainImageUrl").html("<img style='heiht:80px;width:80px;' src=\'"+product.mainImageUrl+"\'/>");
	                       	
	                       	var detailImageUrls="";
	                       	if( product.detailImageUrls ){
	                       		var images = product.detailImageUrls.split(',');
	                       		for( var i=0; i<images.length; i++ ){
	                       			detailImageUrls += "<img style='heiht:80px;width:80px;' src=\'"+product.detailImageUrls+"\'/>";
	                       		}
	                       	}
	                       	
	                       	$("#detailImageUrls").html(detailImageUrls);
	                       	$("#productOrginPrice").html(product.productOrginPrice);
	                       	$("#productHongbao").html(product.productHongbao);
	                       	$("#productPrice").html(product.productPrice);
	                       	$("#note").html(product.note);
                       },
                       url: CONST_URL.GET_PRODUCTS+"?categoryId="+category.id
               	    }); 
               	
                 	$('#productId').combobox('reload', CONST_URL.GET_PRODUCTS+"?categoryId="+category.id); 
               },
               url :  CONST_URL.GET_CATEGORYS//COMMON_URL.getCode + '?type=T_DM_DEMO_TEMPLET_CATEGORY'
               		
           });
       	
       
		
		//初始化商品信息
		$("#name").html(editDataProduct.name);
    	$("#brand").html(editDataProduct.brand);
    	$("#marketProfitPercent").html(editDataProduct.marketProfitPercent);
    	$("#mainImageUrl").html("<img style='heiht:80px;width:80px;' src=\'"+editDataProduct.mainImageUrl+"\'/>");
    	
    	var detailImageUrls="";
    	if( editDataProduct.detailImageUrls ){
    		var images = editDataProduct.detailImageUrls.split(',');
    		for( var i=0; i<images.length; i++ ){
    			detailImageUrls += "<img style='heiht:80px;width:80px;' src=\'"+editDataProduct.detailImageUrls+"\'/>";
    		}
    	}
    	
    	$("#detailImageUrls").html(detailImageUrls);
    	$("#productOrginPrice").html(editDataProduct.productOrginPrice);
    	$("#productHongbao").html(editDataProduct.productHongbao);
    	$("#productPrice").html(editDataProduct.productPrice);
    	$("#note").html(editDataProduct.note);
       	
        $('#form').form().form('loadDataEdit', {
            data: editData
        }); 
    	
    	//保存按钮
    	$('#funcbar').on('click', 'a[data-permit="${name_english}:edit"]', submit);
    	
    	//返回按钮
    	$('#backBtn, #goBack').on('click',backMain);
    });
    
    
    
    //表单提交
    function submit() {
         $("#form").form({
        	 buttons : ['#saveBtn'],
             ajax: {
                 url: CONST_URL.EDIT
             },
             onSubmitSuccess: function (data) {
            	 $.stip({
   	                type:'ok',//显示类型 有info、 ok、 danger
   	                text: '保存成功！',
   	                onBeforeHide: function () {
   	                	backMain();
   	                }
            	 });
              }
         }).form("submit");
    }
    
    
    //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    
    //请求url
    var CONST_URL = {
   		GET_CATEGORYS: basePath + "${common_url}categorys",
       	GET_PRODUCTS: basePath + "${common_url}products",
    	INIT_MAIN: basePath + "${common_url}init",
       	EDIT: basePath + "${common_url}edit"
    };
    
</script>
</body>
</html>